package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.mapper.TaskLogOneMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskLogOne;
import com.ruoyi.system.service.ITaskLogOneService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务一日志Controller
 * 
 * @author ruoyi
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/one/log")
public class TaskLogOneController extends BaseController
{
    @Autowired
    private ITaskLogOneService taskLogOneService;

    @Autowired
    private TaskLogOneMapper taskLogOneMapper;

    /**
     * 查询任务一日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskLogOne taskLogOne)
    {
        startPage();
        List<TaskLogOne> list = taskLogOneService.selectTaskLogOneList(taskLogOne);
        return getDataTable(list);
    }

    /**
     * 导出任务一日志列表
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:export')")
    @Log(title = "任务一日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskLogOne taskLogOne)
    {
        List<TaskLogOne> list = taskLogOneService.selectTaskLogOneList(taskLogOne);
        ExcelUtil<TaskLogOne> util = new ExcelUtil<TaskLogOne>(TaskLogOne.class);
        util.exportExcel(response, list, "任务一日志数据");
    }

    /**
     * 获取任务一日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(taskLogOneService.selectTaskLogOneById(id));
    }

    /**
     * 新增任务一日志
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:add')")
    @Log(title = "任务一日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TaskLogOne taskLogOne)
    {
        return toAjax(taskLogOneService.insertTaskLogOne(taskLogOne));
    }

    /**
     * 修改任务一日志
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:edit')")
    @Log(title = "任务一日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TaskLogOne taskLogOne)
    {
        return toAjax(taskLogOneService.updateTaskLogOne(taskLogOne));
    }

    /**
     * 删除任务一日志
     */
    @PreAuthorize("@ss.hasPermi('system:oneLog:remove')")
    @Log(title = "任务一日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(taskLogOneService.deleteTaskLogOneByIds(ids));
    }



    /**
     * 查询任务一日志 主任务关联的列表
     */
//    @PreAuthorize("@ss.hasPermi('system:oneLog:list')")
    @PostMapping("/taskLogList")
    public AjaxResult taskLogList(@RequestBody TaskLogOne taskLogOne)
    {
        List<TaskLogOne> taskLogOnes = taskLogOneMapper.selectTaskLogOneListByLog(taskLogOne);
        return AjaxResult.success(taskLogOnes);
    }


}
